Added Brctl.get_state, to support upcoming PIF implementation.
authorEwan Mellor <ewan@xensource.com>
Wed, 27 Dec 2006 15:39:32 +0000 (15:39 +0000)
committerEwan Mellor <ewan@xensource.com>
Wed, 27 Dec 2006 15:39:32 +0000 (15:39 +0000)
Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/util/Brctl.py

index 9ae8fdf51dfc0d3555f3e4a8aefdf64e87170aef..5dc9a7fb9f024c1f00c11c617e14a93972b95a22 100644 (file)
@@ -28,6 +28,31 @@ def cmd(p, s):
     if not opts.dryrun:
         os.system(c)
 
+bridgeRE = re.compile(r'([^\t]*)\t*[^\t]*\t*[^\t]*\t*([^\t]*)')
+def get_state():
+    fin = os.popen(CMD_BRCTL + ' show', 'r')
+    try:
+        bridges = {}
+        brlist = None
+        brname = None
+        first = True
+        for line in fin:
+            if first:
+                first = False
+            elif line[0] == '\t':
+                brlist.append(line.strip())
+            else:
+                if brname:
+                    bridges[brname] = brlist
+                m = bridgeRE.match(line)
+                brname = m.group(1)
+                brlist = [m.group(2).strip()]
+        if brname:
+            bridges[brname] = brlist
+        return bridges
+    finally:
+        fin.close()
+
 def vif_bridge_add(params):
     """Add the network interface for vif on dom to a bridge.
     """